using System;
using System.Configuration;
using System.Globalization;
using System.Web;
using System.Web.Mail;
using System.Web.UI;
using System.Xml;

using log4net;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington
	Started:	2007-05-19
	Status:		live	
	Version:	2.0.0
	Build:		20070519
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/
	
/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20070519:
	- Starting point.
	---------------------------------------------------------------------------	*/
	
namespace umlungu.engineX.blogX.TestSiteX {
	/// <summary>
	/// Description of the TestSiteExample class.
	/// <para>Additional information about the class</para>
	/// </summary>
	public class TestSiteExample : x_broker {
		#region Invisible properties
		private bool testing = false;
		private const string logsep = ",";
		private const string logsDir = "Data/Logs/Data/";
		//private NameSpace.WebService webservice;
		#endregion

		#region properties from provisioner
		private x_config config;
		private const string CONFIG_ROOT	= "Example";
		private const string CONFIG_ID		= "webservice";
		
		private const string error_webservice_report	= " Error getting usage report settings from Cactus: ";
		private const string error_webservice_usage		= " Error getting usage report from Cactus: ";
		private const string error_webservice_boosters	= " Error getting booster purchase options: ";
		private const string error_webservice_update	= " Error updating usage report settings to Cactus: ";
		
		private const string error_payment_message	= "Bad payment";
		#endregion

		#region Constant name strings
		private const string logid = "TestSiteExample";
		#endregion

		#region Constant error strings
		private const string error_no_error			= "Not an error";
		private const string error_example			= "TestSiteExample error::";
		private const string error_example_test		= " test error";
		private const string error_example_login	= " Error logging in to account: ";
		private const string error_example_boost	= " Error boosting account: ";
		private const string error_example_email	= " Error updating email notification: ";
		private const string error_example_pay		= " Error making cactus payment: ";
		#endregion

		#region Visible properties
		public static readonly ILog Logger = LogManager.GetLogger(typeof(TestSiteExample));
		#endregion

		#region Constructors/Destructors
		/// <overloads>Constructor</overloads>
		/// <summary>Default constructor</summary>
		/// <param name="thispage">The web application Page object</param>
		public TestSiteExample(displayX thispage) : base(thispage) {
			config = new x_config();
			//webservice = new NameSpace.WebService();
			//webservice.Url = getUrl();
		}
		#endregion

		#region Public methods
		public override void Process(string type) {
			Logger.Info(String.Concat(logid, "_Process:", type));
			switch (type) {
				case "test":	test();		break;
				case "login":	login();		break;
				case "email":	email();		break;
			}
		}
		public void ProcessContent(XmlElement contel) {
			if (testing)
				test(contel);
			else
				nottest(contel);
		}
		#endregion
		
		#region Protected methods
		#endregion
				
		#region Private methods
		/// <summary>Authenticate user</summary>
		/// <remorks>This can have 2 outcomes:
		///	- bad login (already dealt with by exception)
		///	- ok
		/// </remorks>
		private void login() {
			try {
				if (testing) {
					// test code
					test();
				} else {
					// login code
					nottest();
				}
			} catch (x_exception e) {
				throw e;
			} catch (Exception e) {
				throw(new x_exception("error_example_login", String.Concat(error_example, error_example_login, e.Message)));
			}
		}
		/// <summary>Dispatch email</summary>
		private void email() {
			try {
				if (testing) {
					// test code
					test();
				} else {
					// email code
					nottest();
				}
				Logger.Info(String.Concat(logid, "_email:"));
			} catch (x_exception e) {
				throw(new x_exception("error_example_email", String.Concat(error_example, error_example_email, e.Code, " - ", e.Message)));
			} catch (Exception e) {
				throw(new x_exception("error_example_email", String.Concat(error_example, error_example_email, e.Message)));
			}
		}
		#endregion
				
		#region Private utility methods
		private string getUrl() {
			return config.Value(String.Concat(CONFIG_ROOT, "/Url[@id='", CONFIG_ID, "']"));
		}
		private void test() {
		}
		private void test(XmlElement contel) {
			XmlDocument doc = contel.OwnerDocument;
			XmlNode page = contel.SelectSingleNode("//content/page");
		}
		private void nottest() {
		}
		private void nottest(XmlElement contel) {
			XmlDocument doc = contel.OwnerDocument;
			XmlNode page = contel.SelectSingleNode("//content/page");
		}
		#endregion
	}
}
